
const fs = require('fs')
require('http').createServer((req, res) => {
  console.log(req.url)
  switch ( req.url ) {
    case '/home':
      res.write('home')
      res.end()
      break;
    case '/mine':
      res.write('mine')
      res.end()
      break;
    case '/login': 
      fs.readFile( './static/login.html',function ( error , data ) {
        if ( error ) throw error  
        res.write( data )
        res.end()
      })
      break;
    case '/app.js': 
      fs.readFile( './static/app.js',function ( error , data ) {
        if ( error ) throw error  
        res.write( data )
        res.end()
      })
      break;
    case '/cow.jpg':
      fs.readFile( './static/cow.jpg', 'binary', function( error , data ) {
        if( error ) throw error 
        res.write( data, 'binary' )
        res.end()
      })
      break;
    default: 
      res.end('page error.')
      break;
   }
}).listen(8080, () => {
  console.log('http://localhost:8080')
})
